from datetime import datetime, timedelta
from typing import Dict, List, Any, Set, Optional
from utils.sql_generator_util import SQLInsertGenerator
from utils.liquibase_file_util import generate_liquibase_xml

def generator_sql(
    table_structures: List[Dict[str, str]],
    mock_data: Dict[str, Dict[str, List[Dict[str, str]]]],
    db_type: str = "oracle",
):
    generator = SQLInsertGenerator(table_structures, db_type)
    sql_item = {}
    for date in mock_data.keys():
        date_mock_data = mock_data[date]
        print(f"生成 {date} 的{db_type} SQL")
        sqls = generator.generate_inserts(date_mock_data)
        sql_item[date] = sqls

    return sql_item


def generator_liquibase(
    sql_item: Dict[str, List[str]],
    module_name: str,
    comment: str,
    author: str = "test",
    context: str = "common",
):
    liquibase_list = []
    for date in sql_item.keys():
        liquibase_item = {}
        liquibase_item["id"] = f"{module_name}_{date}"
        liquibase_item["author"] = author
        liquibase_item["comment"] = comment
        liquibase_item["context"] = context
        liquibase_item["sql"] = sql_item[date]
        liquibase_list.append(liquibase_item)

    generate_liquibase_xml(liquibase_list, f"output/{module_name}_changelog.xml")


__all__ = ["generator_sql", "generator_liquibase"]
